//
//  DDRenderer_Android.cs
//
//  DD engine for 2d games and apps: https://code.google.com/p/dd-engine/
//
//  Copyright (c) 2013 - Alexander Kirienko
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//
#if DD_PLATFORM_ANDROID

using OpenTK.Graphics.ES11;
public partial class DDRenderer
{
    internal void BeginScene()
    {

    }

    internal void EndScene()
    {

    }

    internal void DrawQuad(DDTexture texture, DDRectangle frame, DDMatrix matrix, DDColor color)
    {
        //GL.PushMatrix();
        //GL.MultMatrix(matrix);

        GL.BindTexture(All.Texture2D, texture.TextureId);
        GL.CullFace(All.FrontAndBack);
        GL.FrontFace(All.Cw);

        float w = (frame.Size.Width * texture.Size.Width);
        float h = (frame.Size.Height * texture.Size.Height);

        DDVector v1 = matrix.TransformPoint(new DDVector(0, h));
        DDVector v2 = matrix.TransformPoint(new DDVector(0, 0));
        DDVector v3 = matrix.TransformPoint(new DDVector(w, 0));
        DDVector v4 = matrix.TransformPoint(new DDVector(w, h));

        var vertices = new float[] {
            v1.X, v1.y, 0,
            v2.X, v2.y, 0,
            v3.X, v3.y, 0,
            v4.X, v4.y, 0,
        };

        var uvs = new float[] {
            frame.Left, frame.Bottom,
            frame.Left, frame.Top,
            frame.Right, frame.Top,
            frame.Right, frame.Bottom
        };

        GL.VertexPointer(3, All.Float, 0, vertices);
        GL.EnableClientState(All.VertexArray);

        GL.TexCoordPointer(2, All.Float, 0, uvs);
        GL.EnableClientState(All.TextureCoordArray);

        GL.EnableClientState(All.ColorArray);
        GL.ColorPointer(4, All.Float, 0, new float[]{
            color.R, color.G, color.B, color.A,
            color.R, color.G, color.B, color.A,
            color.R, color.G, color.B, color.A,
            color.R, color.G, color.B, color.A,
        });

        GL.DrawArrays(All.TriangleFan, 0, 4);

        GL.DisableClientState(All.VertexArray);
        GL.DisableClientState(All.TextureCoordArray);
        GL.DisableClientState(All.ColorArray);


        //GL.PopMatrix();
    }
}

#endif